<?php
/**
 * Workerman-TP6
 *
 * @copyright © 2022 by 技术先锋 All rights reserved。
 * @Created   by PhpStorm.
 * @author    StarsPhp
 * @date      2023/2/7
 * @time      16:24
 */
declare (strict_types=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use utils\server\http\AdapterHttpServer;
use Workerman\Worker;
use Workerman\Timer;
use utils\server\http\Http;

AdapterHttpServer::init();

require_once __DIR__.'/..//thinkHttpRun.php';
$config = \think\facade\Config::get('workerman.http');


$port = $config['protocol_port'];
$http_worker                = new Worker($config['protocol'] . $config['protocol_ip'] . ':' .$port);
// 设置名称，方便status时查看
$http_worker->name = $config['name'] . ':' . $port;
// 设置进程数，gateway进程数建议与cpu核数相同
$http_worker->count = $config['count'];

$http_worker->onWorkerStart = static function (Worker $worker) {
    if ($worker->id === 0) {
        Timer::add(600, function(){
            Http::tryGcSessions();
        });
    }
};

$http_worker->onMessage = static function ($connection, $request) {
    $connection->send(run());
};

// 如果不是在根目录启动，则运行runAll方法
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}

